<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<!--希尔排序
		解析:
		先将整个待排序的记录序列分割成为若干子序列分别进行直接插入排序-->
		<script type="text/javascript">
			function shellSort(arr) {
				var len = arr.length,temp,gap = 1;
				console.time('希尔排序耗时');
				while(gap < len / 5) { // 动态定义间隔序列
					gap = gap * 5 + 1;
				}
				for (gap; gap > 0; gap = Math.floor(gap / 5)) {
					for (var i = gap; i < len; i++) {
						temp = arr[i];
						for (var i = i - gap; j >= 0 && arr[j] > temp; j -= gap) {
							arr[j +gap] = arr[j];
						}
						arr[j + gap] = temp;
					}
				}
				console.timeEnd('希尔排序耗时');
				return arr;
			}
			var arr = [3, 44, 38, 5, 47, 15, 36, 26, 27, 2, 46, 4, 19, 50, 48];
			document.write(shellSort(arr));
		</script>
	</body>
</html>
